from django.db import models

from apps.users.models import BaseModel


class City(BaseModel):
    """城市类"""
    name = models.CharField("城市名", max_length=20)
    desc = models.CharField("描述", max_length=200)

    class Meta:
        verbose_name = "城市"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class CourseOrg(BaseModel):
    """课程机构类"""
    city = models.ForeignKey(City, verbose_name="城市", on_delete=models.CASCADE)
    name = models.CharField("机构名称", max_length=50)
    desc = models.TextField("机构描述")
    tag = models.CharField("机构标签", max_length=10, default="全国知名")
    category = models.CharField("机构类别", max_length=4, default="pxjg",
                                choices=(("pxjg", "培训机构"), ("gr", "个人"), ("gx", "高校")))
    students = models.IntegerField("学习人数", default=0)
    fav_nums = models.IntegerField("收藏人数", default=0)
    click_nums = models.IntegerField("点击人数", default=0)
    image = models.ImageField("logo", max_length=100, upload_to="org/%Y/%m")
    address = models.CharField("机构地址", max_length=150)
    course_nums = models.IntegerField("课程数", default=0)

    class Meta:
        verbose_name = "课程机构"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Teacher(BaseModel):
    """讲师类"""
    org = models.ForeignKey(CourseOrg, verbose_name="所属机构", on_delete=models.CASCADE)
    name = models.CharField("讲师名", max_length=20)
    age = models.IntegerField("年龄", default=18)
    work_years = models.IntegerField("工作年限", default=0)
    work_company = models.CharField("就职公司", max_length=50)
    work_position = models.CharField("公司职位", max_length=50)
    points = models.CharField("教学特点", max_length=50)
    fav_nums = models.IntegerField("收藏人数", default=0)
    click_nums = models.IntegerField("点击人数", default=0)
    image = models.ImageField("头像", max_length=100, upload_to="teacher/%Y/%m")

    class Meta:
        verbose_name = "讲师"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
